package com.iotproject.blogservice.service.impl;

import com.iotproject.blogservice.entity.MyBlog;
import com.iotproject.blogservice.mapper.MBlogMapper;
import com.iotproject.blogservice.service.MBlogService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 博客 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-03-29
 */
@Service
public class MBlogServiceImpl extends ServiceImpl<MBlogMapper, MyBlog> implements MBlogService {

    @Override
    public Map<String, Object> userArticleList(String userId, Integer page, Integer size) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<MyBlog> blogList = baseMapper.userArticleList(userId, page, size);
        QueryWrapper<MyBlog> mBlogQueryWrapper = new QueryWrapper<>();
        mBlogQueryWrapper.eq("user_id", userId);
        Integer total = baseMapper.selectCount(mBlogQueryWrapper);
        Map<String, Object> maps = new HashMap<>();
        maps.put("list", blogList);
        maps.put("total", total);
        return maps;
    }

    @Override
    public void increaseViewCount(String articleId) {
        baseMapper.increaseViewCount(articleId);
    }
}
